package com.oahcfly.chgame.core.mvc;

import java.util.HashMap;

import com.oahcfly.chgame.core.event.CHEvent;
import com.oahcfly.chgame.core.event.CHEventManager;

/**
 * 
 * <pre>
 * 【Model层】
 * 
 * date: 2014-12-3
 * </pre>
 * 
 * @author caohao
 */
public abstract class CHModel {

	public CHScreen screen;

	public CHModel() {
	}

	public CHModel(CHScreen chScreen) {
		screen = chScreen;
	}

	@SuppressWarnings("unchecked")
	public <T extends CHScreen> T getScreen() {
		return (T) screen;
	}

	public void setScreen(CHScreen screen) {
		this.screen = screen;
	}

	/**
	 * 通知UI刷新
	 * @param dataMap 携带的数据
	 */
	public void dispatchUIEvent(HashMap<String, String> dataMap) {
		CHEvent chEvent = new CHEvent(CHEventManager.EVENT_SCREEN_UI, dataMap);
		CHEventManager.getInstance().dispatchEvent(chEvent);
	}
}
